//
//  ZCMVDateViewController.m
//  VoiceMusic
//
//  Created by dllo on 15/10/23.
//  Copyright © 2015年 zhangdeyu. All rights reserved.
//

#import "ZCMVDateViewController.h"
#import "ZCPlayMusicTool.h"
#import <MediaPlayer/MediaPlayer.h>
#import <Masonry.h>
#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEIGHT [UIScreen mainScreen].bounds.size.height
@interface ZCMVDateViewController ()
@property(nonatomic,retain)MPMoviePlayerController * movies;
@end

@implementation ZCMVDateViewController

- (void)viewWillAppear:(BOOL)animated
{
    //外面的歌曲停止播放
    [[ZCPlayMusicTool sharePlay].player pause];
    [ZCPlayMusicTool sharePlay].isplay = NO;
    //点击返回的时候判断播放按钮的状态
    [[NSNotificationCenter defaultCenter] postNotificationName:@"chang" object:nil];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [self.movies pause];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //返回
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [leftButton setImage:[UIImage imageNamed:@"iconfont-fanhui"] forState:UIControlStateNormal];
    leftButton.frame = CGRectMake(0, 0, 30, 30);
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    [leftButton addTarget:self action:@selector(returnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    self.movies = [[MPMoviePlayerController alloc]initWithContentURL:[NSURL URLWithString:self.MVurl]];
    [self.view insertSubview:[self.movies view] atIndex:20];
    [self.movies.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    self.movies.controlStyle = MPMovieControlStyleDefault;
    
    //适应屏幕大小，保持宽高比
    _movies.scalingMode = MPMovieScalingModeAspectFit;
    [_movies play];//播放视频
    
    
}
#pragma mark 返回
- 	(void)returnClick:(UIBarButtonItem *)button
{
    UIWindow *window = [[UIApplication sharedApplication].windows firstObject];
    UIView *view= (UIView *) [window.rootViewController.view viewWithTag:9999];
    view.hidden = NO;
    [self.navigationController popViewControllerAnimated:YES];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
